package model

import (
	"reflect"

	"github.com/jinzhu/gorm"
)

type GetList struct {
	Parent int `json:"parent" default:"-1"`
	Uid    int `json:"uid"`
}

type Person struct {
	gorm.Model
	Name    string `json:"name"`
	Minm    string `json:"minm"`
	Gender  string `json:"gender"`
	Parent  int    `json:"parent" default:"-1"`
	Level   string `json:"level"`
	Partner string `json:"partner"`
	Childs  int    `json:"childs" default:"0"`
	Uid     int    `json:"uid"`
	Desc    string `json:"desc"`
	Born    string `json:"born"`
	Order   int    `json:"order"  default:"0"`
	Death   string `json:"death"`
	Src     string `json:"src"`
}

// 用于更新的时候，过滤掉 grom.Model相关的字段
func (p *Person) UpdateAll() map[string]interface{} {
	m := make(map[string]interface{})
	s := reflect.ValueOf(p).Elem()
	typeOfT := s.Type()
	for i := 0; i < s.NumField(); i++ {
		f := s.Field(i)
		// fmt.Printf("%d:%s %s = %v \n", i, typeOfT.Field(i).Name, f.Type(), f.Interface())
		k := typeOfT.Field(i).Name
		if k == "Model" {
			continue
		}
		m[typeOfT.Field(i).Name] = f.Interface()
	}
	return m
}

type order struct {
	Id    int `json:"id"`
	Order int `json:"order"`
}

type UpdateOrders struct {
	List []order `json:"list"`
}
